
#region Imports

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Sql;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

#endregion

namespace Justa.Data.Provider
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    public class EnterpriseLibraryProvider : DataAccessProvider
    {
        /// <summary>
        /// 
        /// </summary>
        /// 
        private Database database;

        /// <summary>
        /// 
        /// </summary>
        /// 
        public EnterpriseLibraryProvider() 
            : base()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public EnterpriseLibraryProvider(string databaseInstance) 
            : base(databaseInstance)
        {
            this.Init();
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public override void Init()
        {
            database = Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(DatabaseInstance);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        protected Database Database
        {
            get
            {
                return this.database;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <returns></returns>
        /// 
        public override DbConnection CreateConnection()
        {
            return database.CreateConnection();
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        /// <returns></returns>
        /// 
        public override DataSet ExecuteDataSet(DbCommand command)
        {
            return database.ExecuteDataSet(command);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        /// <returns></returns>
        /// 
        public override IDataReader ExecuteReader(DbCommand command)
        {
            return database.ExecuteReader(command);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// <param name="transaction"></param>
        /// 
        /// <returns></returns>
        /// 
        public override IDataReader ExecuteReader(DbCommand command, DbTransaction transaction)
        {
            return database.ExecuteReader(command, transaction);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        public override void ExecuteNonQuery(DbCommand command)
        {
            database.ExecuteNonQuery(command);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// <param name="transaction"></param>
        /// 
        public override void ExecuteNonQuery(DbCommand command, DbTransaction transaction)
        {
            database.ExecuteNonQuery(command, transaction);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// 
        /// <returns></returns>
        /// 
        public override object ExecuteScalar(DbCommand command)
        {
            return database.ExecuteScalar(command);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="query"></param>
        /// 
        /// <returns></returns>
        /// 
        public override DbCommand GetSqlStringCommand(string query)
        {
            return database.GetSqlStringCommand(query);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="name"></param>
        /// 
        /// <returns></returns>
        /// 
        public override DbCommand GetStoredProcCommand(string name)
        {
            return database.GetStoredProcCommand(name);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="name"></param>
        /// <param name="parameters"></param>
        /// 
        /// <returns></returns>
        /// 
        public override DbCommand GetStoredProcCommand(string name, params object[] parameters)
        {
            return database.GetStoredProcCommand(name, parameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="command"></param>
        /// <param name="name"></param>
        /// <param name="dbType"></param>
        /// <param name="value"></param>
        /// 
        public override void AddInParameter(DbCommand command, string name, DbType dbType, object value)
        {
            database.AddInParameter(command, name, dbType, value);
        }
    }
}
